package net.diaowen.common.utils.weixin;

import net.diaowen.common.utils.DiaowenProperty;

public class CreateMenu {

	/**
	 *
	 */
	@SuppressWarnings("resource")
	public static void createMenu() {

		try {

			String appId = DiaowenProperty.APP_ID;

			String baseUrl =DiaowenProperty.BASE_URL;


			String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri="+baseUrl+"/wexin/bind.do&response_type=code&scope=snsapi_base&state=0#wechat_redirect";

			String zuourl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri="+baseUrl+"/wexin/bind.do&response_type=code&scope=snsapi_base&state=0#wechat_redirect";


			String menujson = "{\"button\":[{\"type\":\"view\",\"name\":\"调查问卷\",\"url\":\"" + url + " \"},{\"type\":\"view\",\"name\":\"联系我们\",\"url\":\"" + zuourl + " \"}}";


			//获取Token （获取到的Token2小时有效，可重复使用）
			AccessToken at = WeChatUtil.getAccessToken();

			if (at != null && at.getToken() != null) {

				System.out.println("获取到的TOKEN：\n" + at.getToken());
				// 调用接口创建菜单
				int result = WeChatUtil.createMenu(menujson, at.getToken());
				// 判断菜单创建结果
				if (0 == result)
					System.out.println("菜单创建成功");
				else
					System.out.println("菜单创建失败");
			} else
				System.out.println("菜单创建失败");
		}catch(Exception e){
			e.printStackTrace();

		}

	}

}
